#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv)
{
	int fd, status;

	// 用法示例1：./my_led_test /dev/my_led on			:点灯
	// 用法示例2：./my_led_test /dev/my_led off			:熄灯
	if(argc != 3)
	{
		printf("Too few or too many arguments!\n");
		printf("Usage : %s /dev/my_led on/off\n", argv[0]);
		printf("	 Eg: %s /dev/my_led on\n", argv[0]);
	}

	fd = open(argv[1], O_RDWR);
	if(fd < 0)
	{
		printf("Cannot open file %s\n", argv[1]);
		return -1;
	}


	if(strcmp(argv[2], "on") == 0) // 点灯
	{
		status = 1;
	}
	else // 熄灯
	{
		status = 0;
	}

	write(fd, &status, 1);
	return 0;
}




